import { injectable } from "inversify";
import { commands, Disposable } from "vscode";
import { ICommandNameArgumentTypeMapping } from "./command";
import { ICommandManager } from "./types";

@injectable()
export class CommandManager implements ICommandManager {
    public executeCommand<
        T,
        E extends keyof ICommandNameArgumentTypeMapping,
        U extends ICommandNameArgumentTypeMapping[E]
    >(command: E, ...rest: U): Thenable<T | undefined> {
        return commands.executeCommand<T>(command, ...rest);
    }
    public registerCommand<
        E extends keyof ICommandNameArgumentTypeMapping,
        U extends ICommandNameArgumentTypeMapping[E]
    // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
    >(command: E, callback: (...args: U) => any, thisArg?: any): Disposable {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        return commands.registerCommand(command, callback as any, thisArg);
    }
}